unit RegistryUtils;

interface

function  GetSetting(SName : String) : String;
procedure  SetSetting(SName : String; Value : String);
function  GetIntSetting(SName : String; ADefault : Integer) : Integer;
procedure  SetIntSetting(SName : String; Value : Integer);

implementation
uses
  Windows, Registry, SpisCnst, SysUtils, Forms;


function  GetSetting(SName : String) : String;
var KeyName : String;
begin
  Result := '';
  with TRegistry.Create do
    try
      RootKey:=HKEY_CURRENT_USER;
      if not OpenKey(AppRootKey, False) then
        Exit;
      KeyName:=AppRootKey + '\Settings\'+SName;
      if not OpenKey(KeyName, False) then
      	Exit;
      Result :=ReadString('Value');
    finally
      Free;
    end;
end;

procedure  SetSetting(SName : String; Value : String);
var KeyName : String;
begin
  with TRegistry.Create do
    try
      RootKey:=HKEY_CURRENT_USER;
      OpenKey(AppRootKey, True);
      KeyName:=AppRootKey + '\Settings\'+SName;
      if not OpenKey(KeyName, True) then
      	Exit;
      WriteString('Value', Value);
    finally
      Free;
    end;
end;

function  GetIntSetting(SName : String; ADefault : Integer) : Integer;
var KeyName : String;
begin
  Result := ADefault;
  with TRegistry.Create do
    try
      RootKey:=HKEY_CURRENT_USER;
      if not OpenKey(AppRootKey, False) then
        Exit;
      KeyName:=AppRootKey + '\Settings\'+SName;
      if not OpenKey(KeyName, False) then
      	Exit;
      Result :=ReadInteger('Value');
    finally
      Free;
    end;
end;

procedure  SetIntSetting(SName : String; Value : Integer);
var KeyName : String;
begin
  with TRegistry.Create do
    try
      RootKey:=HKEY_CURRENT_USER;
      OpenKey(AppRootKey, True);
      KeyName:=AppRootKey + '\Settings\'+SName;
      if not OpenKey(KeyName, True) then
      	Exit;
      WriteInteger('Value', Value);
    finally
      Free;
    end;
end;

end.
